﻿<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="../helpproject.xsl" ?>
<topic template="Default" lasteditedby="Geert" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../helpproject.xsd">
  <title translate="true">Declaring properties</title>
  <body>
    <header>
      <para styleclass="Heading1"><text styleclass="Heading1" translate="true">Declaring properties</text></para>
    </header>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">The next step to learn on the </text><link displaytype="text" defaultstyle="true" type="topiclink" href="T_Catel_Data_ModelBase" styleclass="Normal" translate="true">ModelBase</link><text styleclass="Normal" translate="true"> class is how to declare properties. There are several types of properties, and they will all be handled in this part of the documentation.</text></para>
    <para styleclass="Heading1"><text styleclass="Heading1" translate="true">Simple properties</text></para>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">This example shows how to declare the simplest property. In this example, a string property with a default value will be declared with the use of a code snippet.</text></para>
    <para styleclass="Heading2"><text styleclass="Heading2" translate="true">Code snippets</text></para>
    <list id="14" type="ul" listtype="bullet" formatstring="·" format-charset="SYMBOL_CHARSET" levelreset="true" legalstyle="false" startfrom="1" styleclass="Normal" style="font-family:Symbol; font-size:10pt; color:#000000;">
      <li styleclass="Normal"><text styleclass="Normal" translate="true">modelprop - Declares a simple property on a model</text></li>
    </list>
    <para styleclass="Heading2"><text styleclass="Heading2" translate="true">Steps</text></para>
    <list id="15" type="ol" listtype="decimal" formatstring="%0:s." format-charset="DEFAULT_CHARSET" levelreset="true" legalstyle="false" startfrom="1" styleclass="Normal (list)" style="font-family:Arial; font-size:10pt; color:#000000;">
      <li styleclass="Normal (list)"><text styleclass="Normal (list)" translate="true">Open </text><text styleclass="Normal (list)" style="font-style:italic;" translate="true">FirstModel.cs</text><text styleclass="Normal (list)" translate="true"> created in the previous step.</text></li>
      <li styleclass="Normal (list)"><text styleclass="Normal (list)" translate="true">In the </text><text styleclass="Normal (list)" style="font-style:italic;" translate="true">Properties</text><text styleclass="Normal (list)" translate="true"> region, use the code snippet </text><text styleclass="Normal (list)" style="font-style:italic;" translate="true">modelprop</text><text styleclass="Normal (list)" translate="true">, and use the following values:</text></li>
    </list>
    <para styleclass="Normal"><table styleclass="Default" rowcount="5" colcount="2">
      <tr style="vertical-align:top">
        <td style="width:227px;">
          <para styleclass="Normal (list)"><text styleclass="Normal (list)" style="font-weight:bold;" translate="true">Code snippet item</text></para>
        </td>
        <td style="width:458px;">
          <para styleclass="Normal (list)"><text styleclass="Normal (list)" style="font-weight:bold;" translate="true">Value</text></para>
        </td>
      </tr>
      <tr style="vertical-align:top">
        <td style="width:227px;">
          <para styleclass="Normal (list)"><text styleclass="Normal (list)" translate="true">description</text></para>
        </td>
        <td style="width:458px;">
          <para styleclass="Normal (list)"><text styleclass="Normal (list)" translate="true">Gets or sets the simple property</text></para>
        </td>
      </tr>
      <tr style="vertical-align:top">
        <td style="width:227px;">
          <para styleclass="Normal (list)"><text styleclass="Normal (list)" translate="true">type</text></para>
        </td>
        <td style="width:458px;">
          <para styleclass="Normal (list)"><text styleclass="Normal (list)" translate="true">string</text></para>
        </td>
      </tr>
      <tr style="vertical-align:top">
        <td style="width:227px;">
          <para styleclass="Normal (list)"><text styleclass="Normal (list)" translate="true">name</text></para>
        </td>
        <td style="width:458px;">
          <para styleclass="Normal (list)"><text styleclass="Normal (list)" translate="true">SimpleProperty</text></para>
        </td>
      </tr>
      <tr style="vertical-align:top">
        <td style="width:227px;">
          <para styleclass="Normal (list)"><text styleclass="Normal (list)" translate="true">defaultvalue</text></para>
        </td>
        <td style="width:458px;">
          <para styleclass="Normal (list)"><text styleclass="Normal (list)" translate="true">&quot;Simple property&quot;</text></para>
        </td>
      </tr>
    </table></para>
    <para styleclass="Heading2"><text styleclass="Heading2" translate="true">Code</text></para>
    <para styleclass="Code Example"><text styleclass="Code Example" style="font-weight:normal; font-style:italic; color:#000000;" translate="true">/// &lt;summary&gt; </text><br/><text styleclass="Code Example" style="font-weight:normal; font-style:italic; color:#000000;" translate="true">/// Gets or sets the simple property.</text><br/><text styleclass="Code Example" style="font-weight:normal; font-style:italic; color:#000000;" translate="true">/// &lt;/summary&gt; </text><br/><text styleclass="Code Example" style="font-weight:bold; font-style:normal; color:#000000;" translate="true">public</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true"> </text><text styleclass="Code Example" style="font-weight:bold; font-style:normal; color:#000000;" translate="true">string</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true"> </text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">SimpleProperty</text><br/><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">{</text><br/><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true">    </text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">get</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true"> </text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">{</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true"> </text><text styleclass="Code Example" style="font-weight:bold; font-style:normal; color:#000000;" translate="true">return</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true"> </text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">GetValue&lt;</text><text styleclass="Code Example" style="font-weight:bold; font-style:normal; color:#000000;" translate="true">string</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">&gt;(SimplePropertyProperty);</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true"> </text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">}</text><br/><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true">    </text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">set</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true"> </text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">{</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true"> </text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">SetValue(SimplePropertyProperty,</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true"> </text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">value);</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true"> </text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">}</text><br/><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">}</text><br/><br/><text styleclass="Code Example" style="font-weight:normal; font-style:italic; color:#000000;" translate="true">/// &lt;summary&gt; </text><br/><text styleclass="Code Example" style="font-weight:normal; font-style:italic; color:#000000;" translate="true">/// Register the SimpleProperty property so it is known in the class.</text><br/><text styleclass="Code Example" style="font-weight:normal; font-style:italic; color:#000000;" translate="true">/// &lt;/summary&gt; </text><br/><text styleclass="Code Example" style="font-weight:bold; font-style:normal; color:#000000;" translate="true">public</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true"> </text><text styleclass="Code Example" style="font-weight:bold; font-style:normal; color:#000000;" translate="true">static</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true"> </text><text styleclass="Code Example" style="font-weight:bold; font-style:normal; color:#000000;" translate="true">readonly</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true"> </text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">PropertyDataSimplePropertyProperty</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true"> </text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">=</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true"> </text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">RegisterProperty(&quot;SimpleProperty&quot;,</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true"> </text><text styleclass="Code Example" style="font-weight:bold; font-style:normal; color:#000000;" translate="true">typeof</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">(</text><text styleclass="Code Example" style="font-weight:bold; font-style:normal; color:#000000;" translate="true">string</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">),</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true"> </text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">&quot;Simple property&quot;);</text></para>
    <para styleclass="Heading1"><text styleclass="Heading1" translate="true">Properties with property change callback</text></para>
    <para styleclass="Heading2"><text styleclass="Heading2" translate="true">Code snippets</text></para>
    <list id="14" type="ul" listtype="bullet" formatstring="·" format-charset="SYMBOL_CHARSET" levelreset="true" legalstyle="false" startfrom="1" styleclass="Normal" style="font-family:Symbol; font-size:10pt; color:#000000;">
      <li styleclass="Normal"><text styleclass="Normal" translate="true">modelpropchanged - Declares a simple property on a model with a property changed callback</text></li>
    </list>
    <para styleclass="Heading2"><text styleclass="Heading2" translate="true">Steps</text></para>
    <list id="5" type="ol" listtype="decimal" formatstring="%0:s." format-charset="DEFAULT_CHARSET" levelreset="true" legalstyle="false" startfrom="1" styleclass="Normal (list)" style="font-family:Arial; font-size:10pt; color:#000000;">
      <li styleclass="Normal (list)"><text styleclass="Normal (list)" translate="true">Open </text><text styleclass="Normal (list)" style="font-style:italic;" translate="true">FirstModel.cs</text><text styleclass="Normal (list)" translate="true"> created in the previous step.</text></li>
      <li styleclass="Normal (list)"><text styleclass="Normal (list)" translate="true">In the </text><text styleclass="Normal (list)" style="font-style:italic;" translate="true">Properties</text><text styleclass="Normal (list)" translate="true"> region, use the code snippet </text><text styleclass="Normal (list)" style="font-style:italic;" translate="true">modelpropchanged</text><text styleclass="Normal (list)" translate="true">, and use the following values:</text></li>
    </list>
    <para styleclass="Normal"><table styleclass="Default" rowcount="5" colcount="2">
      <tr style="vertical-align:top">
        <td style="width:227px;">
          <para styleclass="Normal (list)"><text styleclass="Normal (list)" style="font-weight:bold;" translate="true">Code snippet item</text></para>
        </td>
        <td style="width:458px;">
          <para styleclass="Normal (list)"><text styleclass="Normal (list)" style="font-weight:bold;" translate="true">Value</text></para>
        </td>
      </tr>
      <tr style="vertical-align:top">
        <td style="width:227px;">
          <para styleclass="Normal (list)"><text styleclass="Normal (list)" translate="true">description</text></para>
        </td>
        <td style="width:458px;">
          <para styleclass="Normal (list)"><text styleclass="Normal (list)" translate="true">Gets or sets the callback property</text></para>
        </td>
      </tr>
      <tr style="vertical-align:top">
        <td style="width:227px;">
          <para styleclass="Normal (list)"><text styleclass="Normal (list)" translate="true">type</text></para>
        </td>
        <td style="width:458px;">
          <para styleclass="Normal (list)"><text styleclass="Normal (list)" translate="true">string</text></para>
        </td>
      </tr>
      <tr style="vertical-align:top">
        <td style="width:227px;">
          <para styleclass="Normal (list)"><text styleclass="Normal (list)" translate="true">name</text></para>
        </td>
        <td style="width:458px;">
          <para styleclass="Normal (list)"><text styleclass="Normal (list)" translate="true">CallbackProperty</text></para>
        </td>
      </tr>
      <tr style="vertical-align:top">
        <td style="width:227px;">
          <para styleclass="Normal (list)"><text styleclass="Normal (list)" translate="true">defaultvalue</text></para>
        </td>
        <td style="width:458px;">
          <para styleclass="Normal (list)"><text styleclass="Normal (list)" translate="true">&quot;Callback property&quot;</text></para>
        </td>
      </tr>
    </table></para>
    <para styleclass="Heading2"><text styleclass="Heading2" translate="true">Code</text></para>
    <para styleclass="Code Example"><text styleclass="Code Example" style="font-weight:normal; font-style:italic; color:#000000;" translate="true">/// &lt;summary&gt; </text><br/><text styleclass="Code Example" style="font-weight:normal; font-style:italic; color:#000000;" translate="true">/// Gets or sets the callback property.</text><br/><text styleclass="Code Example" style="font-weight:normal; font-style:italic; color:#000000;" translate="true">/// &lt;/summary&gt; </text><br/><text styleclass="Code Example" style="font-weight:bold; font-style:normal; color:#000000;" translate="true">public</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true"> </text><text styleclass="Code Example" style="font-weight:bold; font-style:normal; color:#000000;" translate="true">string</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true"> </text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">CallbackProperty</text><br/><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">{</text><br/><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true">    </text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">get</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true"> </text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">{</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true"> </text><text styleclass="Code Example" style="font-weight:bold; font-style:normal; color:#000000;" translate="true">return</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true"> </text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">GetValue&lt;</text><text styleclass="Code Example" style="font-weight:bold; font-style:normal; color:#000000;" translate="true">string</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">&gt;(CallbackPropertyProperty);</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true"> </text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">}</text><br/><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true">    </text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">set</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true"> </text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">{</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true"> </text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">SetValue(CallbackPropertyProperty,</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true"> </text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">value);</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true"> </text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">}</text><br/><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">}</text><br/><br/><text styleclass="Code Example" style="font-weight:normal; font-style:italic; color:#000000;" translate="true">/// &lt;summary&gt; </text><br/><text styleclass="Code Example" style="font-weight:normal; font-style:italic; color:#000000;" translate="true">/// Register the CallbackProperty property so it is known in the class.</text><br/><text styleclass="Code Example" style="font-weight:normal; font-style:italic; color:#000000;" translate="true">/// &lt;/summary&gt; </text><br/><text styleclass="Code Example" style="font-weight:bold; font-style:normal; color:#000000;" translate="true">public</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true"> </text><text styleclass="Code Example" style="font-weight:bold; font-style:normal; color:#000000;" translate="true">static</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true"> </text><text styleclass="Code Example" style="font-weight:bold; font-style:normal; color:#000000;" translate="true">readonly</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true"> </text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">PropertyDataCallbackPropertyProperty</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true"> </text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">=</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true"> </text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">RegisterProperty(&quot;CallbackProperty&quot;,</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true"> </text><text styleclass="Code Example" style="font-weight:bold; font-style:normal; color:#000000;" translate="true">typeof</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">(</text><text styleclass="Code Example" style="font-weight:bold; font-style:normal; color:#000000;" translate="true">string</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">),</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true"> </text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">&quot;Callback property&quot;,</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true"> </text><br/><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true">    </text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">(sender,</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true"> </text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">e)</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true"> </text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">=&gt;</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true"> </text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">((FirstDataObject)sender).OnCallbackPropertyChanged());</text><br/><br/><text styleclass="Code Example" style="font-weight:normal; font-style:italic; color:#000000;" translate="true">/// &lt;summary&gt; </text><br/><text styleclass="Code Example" style="font-weight:normal; font-style:italic; color:#000000;" translate="true">/// Called when the CallbackProperty property has changed.</text><br/><text styleclass="Code Example" style="font-weight:normal; font-style:italic; color:#000000;" translate="true">/// &lt;/summary&gt; </text><br/><text styleclass="Code Example" style="font-weight:bold; font-style:normal; color:#000000;" translate="true">private</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true"> </text><text styleclass="Code Example" style="font-weight:bold; font-style:normal; color:#000000;" translate="true">void</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true"> </text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">OnCallbackPropertyChanged()</text><br/><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">{</text><br/><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true">    </text><text styleclass="Code Example" style="font-weight:normal; font-style:italic; color:#000000;" translate="true">// TODO: Implement logic</text><br/><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">}</text></para>
  </body>
</topic>
